package com.ruoyi.web.controller.project;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.InviteBids;
import com.ruoyi.system.service.IInviteBidsService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 项目招标Controller
 * 
 * @author zhaonz
 * @date 2023-06-02
 */
@Controller
@RequestMapping("/project/bids")
public class InviteBidsController extends BaseController
{
    private String prefix = "project/bids";

    @Autowired
    private IInviteBidsService inviteBidsService;

    @RequiresPermissions("system:bids:view")
    @GetMapping()
    public String bids()
    {
        return prefix + "/bids";
    }

    /**
     * 查询项目招标列表
     */
    @RequiresPermissions("system:bids:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(InviteBids inviteBids)
    {
        startPage();
        List<InviteBids> list = inviteBidsService.list(inviteBids);
        return getDataTable(list);
    }

    /**
     * 导出项目招标列表
     */
    @RequiresPermissions("system:bids:export")
    @Log(title = "项目招标", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(InviteBids inviteBids)
    {
        List<InviteBids> list = inviteBidsService.list(inviteBids);
        ExcelUtil<InviteBids> util = new ExcelUtil<InviteBids>(InviteBids.class);
        return util.exportExcel(list, "项目招标数据");
    }

    /**
     * 新增项目招标
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存项目招标
     */
    @RequiresPermissions("system:bids:add")
    @Log(title = "项目招标", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(InviteBids inviteBids)
    {
        return toAjax(inviteBidsService.save(inviteBids));
    }

    /**
     * 修改项目招标
     */
    @RequiresPermissions("system:bids:edit")
    @GetMapping("/edit/{inviteBidsId}")
    public String edit(@PathVariable("inviteBidsId") Long inviteBidsId, ModelMap mmap)
    {
        InviteBids inviteBids = inviteBidsService.getById(inviteBidsId);
        mmap.put("inviteBids", inviteBids);
        return prefix + "/edit";
    }

    /**
     * 修改保存项目招标
     */
    @RequiresPermissions("system:bids:edit")
    @Log(title = "项目招标", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(InviteBids inviteBids)
    {
        return toAjax(inviteBidsService.updateById(inviteBids));
    }

    /**
     * 删除项目招标
     */
    @RequiresPermissions("system:bids:remove")
    @Log(title = "项目招标", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(inviteBidsService.removeByIds(ids));
    }
}
